<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>项目受理
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="projectId" label="项目ID" width="80" align="center"></el-table-column>
                <el-table-column prop="projectName" label="项目名称"></el-table-column>
                <el-table-column prop="projectContent" label="项目内容"></el-table-column>
                <el-table-column prop="projectResult" label="项目情况"></el-table-column>
                <el-table-column prop="userName" label="申请人"></el-table-column>
                <el-table-column prop="projectUpdateTime" label="受理时间"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-document-delete"
                                @click="handleEdit(scope.$index, scope.row)"
                        >不属于受理范围
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-document-remove"
                                @click="handleEdit1(scope.$index, scope.row)"
                        >资料不齐全
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-document-checked"
                                @click="successAccept(scope.$index, scope.row)"
                        >成功受理
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="pagination">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :current-page="curr"
                        :total="pageTotal"
                        :page-size="5"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
                <div>修改成功</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 受理成功弹出框 -->
        <el-dialog title="选择你要提交的事项" :visible.sync="successVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <div>
                    <el-select v-model="value" multiple placeholder="请选择"  @change="getMessage($event)">
                        <el-option
                                v-for="item in options"
                                :key="item.userId"
                                :label="item.userName"
                                :value="item.userName">
                        </el-option>
                    </el-select>
                </div>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="successVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import {fetchData} from '../../api/index';

    export default {
        name: 'project',
        data() {
            return {
                options : [],
                value: '',
                userNames :[],
                query: {
                    projectId: '',
                    projectStatus: '',
                    projectResult: '',
                    pageIndex: 1,
                    pageSize: 10
                },
                curr: 1,
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                successVisible: false,
                pageTotal: 0,
                form: {},
                idx: -1,
                id: -1,

            }
        },
        mounted() {
            this.getData({});
        },
        methods: {

            getData(params) {
                var vm = this;
                this.$axios.get('/acceptedItems', {
                    params: params
                }).then(resp => {
                    if (resp.data.success) {
                        //页面数据
                        vm.tableData = resp.data.data.records;
                        //总条数
                        vm.pageTotal = resp.data.data.total;
                        //当前页
                        vm.query.pageIndex = resp.data.data.current;
                    }
                })
            },


            // 编辑操作
            handleEdit(index, row) {
                this.editVisible = true;
                this.$axios.get("/outAcceptRange",{
                    params :{projectId:row.projectId}
                })
                this.getData()
            },
            handleEdit1(index, row) {
                this.editVisible = true;
                this.$axios.get("/incompleteData",{
                    params :{projectId:row.projectId}
                })
                this.getData()
            },
            /**
             * 成功受理操作
             * @param index
             * @param row
             */
            successAccept(index, row) {
                let _this = this
                this.form = row;
                this.successVisible = true;
                this.$axios.get("/selectAllByUserBm")
                    .then(resp => {
                        if (resp.data.success) {
                            _this.options = resp.data.data
                        }
                    })
            },

            getMessage(e){
                let _this = this
                _this.userNames = e
            },

            // 保存成功受理的编辑
            saveEdit() {
                let _this = this
                var f = this.form;
                this.successVisible = false
                this.$axios.get('/insertSxByUser',{params:{
                    projectId:f.projectId,
                    userNames:_this.userNames.toString(),
                }}).then(resp => {
                    if (resp.data.success) {
                        this.$message.success(`添加成功`);
                        this.getData()
                        this.$set(this.tableData, this.idx, this.form);
                    }
                })
            },
            // 分页导航
            handlePageChange(curr) {
                var f = this.query;
                var params = {
                    pageIndex: curr,
                }
                this.getData(params);
            }
        }
    };
</script>

<style scoped>
    .table {
        width: 100%;
        font-size: 14px;
    }
</style>
